#include "stdafx.h"
#include "GameObject.h"

#include <algorithm>

namespace Cinetic
{
    void GameObject::add_component( std::shared_ptr<Component> comp )
    {
        ME_ASSERT(comp != nullptr, "Cannot add null component");
        m_components.push_back(comp);
        ComponentAdded( shared_from_this(), comp );
    }

    void GameObject::remove_component( std::shared_ptr<Component> comp )
    {
        ME_ASSERT(comp != nullptr, "Cannot remove null component");
        auto it = std::find(m_components.begin(), m_components.end(), comp);
        if (it != m_components.end()) {
            m_components.erase(it);
            ComponentRemoved( shared_from_this(), comp );
        }
    }

    GameObject::ComponentIterator GameObject::component_begin()
    {
        return m_components.begin();
    }

    GameObject::ComponentIterator GameObject::component_end()
    {
        return m_components.end();
    }

}